package Service;

import Service.Implement.systemServiceImplement;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;
import java.util.TimerTask;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class TimerSchedule {

    public static void main(String[] args) {
        LocalDate localDate = LocalDate.now();



        LocalDateTime maxTime = localDate.atTime(LocalTime.MAX);

        Long milliSecond = maxTime.toInstant(ZoneOffset.of("+8")).toEpochMilli();


        Runnable runnable1=new Runnable() {
            @Override
            public void run() {
                systemService systemService=new systemServiceImplement();
                systemService.updateBitsMap();
            }
        };
        Runnable runnable2=new Runnable() {
            @Override
            public void run() {
                systemService systemService=new systemServiceImplement();
                systemService.updateUserPk(localDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")).toString());
            }
        };

        ScheduledExecutorService scheduledExecutorService= Executors.newSingleThreadScheduledExecutor();
        scheduledExecutorService.scheduleAtFixedRate(runnable1, milliSecond-System.currentTimeMillis() ,60*60*24, TimeUnit.SECONDS);
        scheduledExecutorService.scheduleAtFixedRate(runnable2, milliSecond-System.currentTimeMillis() ,60*60*24*30, TimeUnit.SECONDS);

    }
}
